package com.flutter_ecg.flutter_ecg

import android.content.Intent
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugins.GeneratedPluginRegistrant
import com.flutter_ecg.flutter_ecg.ecgapplication.ecgdevicescan.ECGDeviceScanActivity
import android.util.Log
import androidx.annotation.NonNull


class MainActivity : FlutterActivity() {
    override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
        GeneratedPluginRegistrant.registerWith(flutterEngine)
        val _channel = MethodChannel(flutterEngine.getDartExecutor(), CHANNEL)
        if (_channel != null) {
            channel = _channel;
        }
        _channel.setMethodCallHandler(
            object : MethodCallHandler {
                override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
                    if (call.method.equals("goToNativePage")) {
                        // 参数
                        val params = call.argument("key") ?: "default key"

                        // 跳转
                        val intent = Intent(this@MainActivity, ECGDeviceScanActivity::class.java)
                        intent.putExtra("activityKey", params)
                        startActivity(intent)
                        result.success(params)
                    } else {
                        result.notImplemented()
                    }
                }
            })
    }

    companion object {
        private const val CHANNEL = "plugin_ecg"
        private var channel:MethodChannel? = null;
        @JvmStatic fun sendData(ecgSmartResult:String, tarFilePath:String,userInfo:String, userData:String) {
            Log.i("检测结果===================", ecgSmartResult);
            Log.i("检测文件路径====================", tarFilePath);
            channel?.invokeMethod("sendData", ecgSmartResult);
        }
    }
}